package com.hw.dagl.controller;

import static com.hw.utils.DESCrypt.encrypt;
import static com.hw.utils.DESCrypt.toHexString;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hw.dagl.model.DriverView;
import com.hw.dagl.model.Sys_Role;
import com.hw.dagl.model.Sys_User;
import com.hw.dagl.model.Vehicle;
import com.hw.dagl.service.YxxxService;
import com.hw.dagl.service.impl.FrmCodeServiceImpl;
import com.hw.dao.utils.ControllerUtil;
import com.hw.dao.utils.GcPage;
import com.hw.dao.utils.Page;
import com.hw.dao.utils.PageUtil;
import org.apache.commons.lang.StringUtils;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author Administrator
 * 影像信息
 */
@Controller
public class YxxxController extends BaseController{
	@Resource
	private YxxxService YxxxServiceImpl;
	/**
	 * 跳转到影像审核页面
	 */
	@RequestMapping(method=RequestMethod.GET)
	public String yxsh(HttpServletResponse response){
		return "yxsh/vehicle/yxsh";
	}
	
	/**
	 * 分页显示机动车档案审核列表
	 */
	@RequestMapping(method=RequestMethod.POST)	
	public void findYxshPage(HttpServletRequest request,HttpServletResponse response,
								Page<Vehicle> pages,Vehicle info,String startTime,String endTime){
		Sys_User user=(Sys_User) request.getSession().getAttribute("user");
		Page<Vehicle> list = YxxxServiceImpl.findYxshxx(pages, info,startTime,endTime,user);
		ControllerUtil.renderJson(response, list, "encoding:UTF-8","no-cache:false");
	}

	/**
	 * 通过身份证号码查询驾照信息
	 * @param
	 */
	@RequestMapping(method=RequestMethod.POST)
	public void queryBySfz(HttpServletResponse response,String sfzmhm){
		DriverView driverView=YxxxServiceImpl.queryBySfz(sfzmhm);
		ControllerUtil.renderJson(response, driverView, "encoding:UTF-8","no-cache:false");
	}
	
	/**
	 * 根据车辆记录首次查询影像审核档案详情，第一次进入详情
	 * @param request
	 * @param response
	 */
	/*@RequestMapping(method = RequestMethod.GET)
	public ModelAndView findYxshByxhFirstIn(HttpServletRequest request,HttpServletResponse response,GcPage<Vehicle> pages,
			Vehicle info,String startTime,String endTime){
		ModelAndView mv = new ModelAndView("yxsh/vehicle/yxshxq");
		GcPage<Vehicle> page=YxxxServiceImpl.findYxshByxhFirstIn(pages,info,startTime,endTime);
		Document doc=null;
		try {
			doc = DocumentHelper.parseText(page.getRows().get(0).getTpurl());
		} catch (DocumentException e1) {
			e1.printStackTrace();
		}
		 Element root = doc.getRootElement();
		 List nodes = root.elements();
		 List<Vehicle> listTpurl = new ArrayList<Vehicle>();
		 for (Iterator<?> it = nodes.iterator(); it.hasNext();) {
			 Vehicle obj =new Vehicle();
		 Element e = (Element) it.next();
		 obj.setId(e.attributeValue("id"));
		 obj.setSingleIpaddress(e.getStringValue());
		 listTpurl.add(obj);
		 }
		mv.addObject("list",listTpurl);
		mv.addObject("page",page);
		mv.addObject("startTime",startTime);
		mv.addObject("endTime",endTime);
		mv.addObject("vehicleObj",page.getRows().get(0));
		return mv;
	}*/
	/**
	 * 机动车档案详情
	 * @param request
	 * @param response
	 * @param page
	 * @param info
	 * @param startTime
	 * @param endTime
	 * @param xhs
	 * @return
	 */
		@RequestMapping(method = RequestMethod.GET)
		public ModelAndView findYxshxqByxh(HttpServletRequest request,HttpServletResponse response,PageUtil page,
				Vehicle info,String startTime,String endTime,String xhs){
			ModelAndView mv = new ModelAndView("yxsh/vehicle/yxshxq");
			String xh=info.getXh();
			String preXh="";//上一个序号
			String currentXh="";//当前序号
			String nextXh="";//下一个序号
			if(StringUtils.isNotEmpty(xh)){
			    String[] xhArr=xh.split(",");
			    preXh=xhArr[0];
			    currentXh=xhArr[1];
			    nextXh=xhArr[2];
			}
			//只有到了边界，才需要查询数据
			boolean pageUpFlag=false;
	        boolean pageDownFlag=false;
	        Long pageNumber=page.getCurrentPage();//当前页数
	        Long totalPage=page.getTotalPage();//总页数
	        if(preXh.equals("0") && pageNumber>1){
	            //如果pageUp为0,证明当前xh已经是当前页面第一条记录，这时应该查询上一页的数据
	            pageUpFlag=true;
	        }else if(nextXh.equals("0") && pageNumber<=totalPage){
	            //且不是最后一页
	            //如果pageDown为0,证明当前页面已经走到最后一条记录了，这时应该查询下一页的数据
	            pageDownFlag=true;
	        }
	        if(pageUpFlag || pageDownFlag){
	            int locateIndex=0;//当前xh在新的查询数据中的位置
	            //遇到分页的时候就多查点数据
	            List<Vehicle> vehicles=YxxxServiceImpl.queryVehicleList(
	                    info,startTime,endTime,page);
	            int size=vehicles.size();
	            for(int i=0;i<size;i++){
	                Vehicle tempVehicle=vehicles.get(i);
	                String newXh=tempVehicle.getXh();
	                if(currentXh.equals(newXh)){
	                    locateIndex=i;
	                }
	                if(i==0){
	                    xhs=newXh;
	                }else{
	                    xhs=xhs+","+newXh;
	                }
	            }
	            if(pageUpFlag){
	                //上一页
	                preXh=vehicles.get(locateIndex-1).getXh();
	            }else if(pageDownFlag){
	                //下一页
	                if(locateIndex+1<size){
	                    nextXh=vehicles.get(locateIndex+1).getXh();
	                }
	            }
	        }
			info.setXh(currentXh);
			info=YxxxServiceImpl.findYxshByxhFirstIn(info,startTime,endTime);
			Document doc=null;
			try {
				doc = DocumentHelper.parseText(info.getTpurl()==null?"":info.getTpurl());
			} catch (DocumentException e1) {
				e1.printStackTrace();
			}
			List<Vehicle> listTpurl = new ArrayList<Vehicle>();
			if(null!=doc){
				Element root = doc.getRootElement();
				List nodes = root.elements();

				for (Iterator<?> it = nodes.iterator(); it.hasNext();) {
					Vehicle obj =new Vehicle();
					Element e = (Element) it.next();
					obj.setId(e.attributeValue("id"));
					try {
						obj.setSingleIpaddress(toHexString(encrypt(e.getStringValue(), "ahhwxxjs")).toUpperCase());
					} catch (Exception e1) {
						e1.printStackTrace();
					}
					listTpurl.add(obj);
				}
			}

			mv.addObject("listTpurl",listTpurl);
			mv.addObject("info",info);
			mv.addObject("preXh",preXh);
			mv.addObject("xhs",xhs);
			mv.addObject("nextXh",nextXh);
			mv.addObject("startTime",startTime);
			mv.addObject("endTime",endTime);
			mv.addObject("pageInfo",page);
			return mv;
		}
	/**
	 * 机动车档案审核详情
	 * @param request
	 * @param response
	 * @param page
	 * @param info
	 * @param startTime
	 * @param endTime
	 * @param xhs
	 * @return
	 */
		@RequestMapping(method = RequestMethod.GET)
		public ModelAndView findYxshByxhFirstIn(HttpServletRequest request,HttpServletResponse response,PageUtil page,
				Vehicle info,String startTime,String endTime,String xhs){
			ModelAndView mv = new ModelAndView("yxsh/vehicle/yxshxqAction");
			String xh=info.getXh();
			String preXh="";//上一个序号
			String currentXh="";//当前序号
			String nextXh="";//下一个序号
			if(StringUtils.isNotEmpty(xh)){
			    String[] xhArr=xh.split(",");
			    preXh=xhArr[0];
			    currentXh=xhArr[1];
			    nextXh=xhArr[2];
			}
			//只有到了边界，才需要查询数据
			boolean pageUpFlag=false;
	        boolean pageDownFlag=false;
	        Long pageNumber=page.getCurrentPage();//当前页数
	        Long totalPage=page.getTotalPage();//总页数
	        if(preXh.equals("0") && pageNumber>1){
	            //如果pageUp为0,证明当前xh已经是当前页面第一条记录，这时应该查询上一页的数据
	            pageUpFlag=true;
	        }else if(nextXh.equals("0") && pageNumber<=totalPage){
	            //且不是最后一页
	            //如果pageDown为0,证明当前页面已经走到最后一条记录了，这时应该查询下一页的数据
	            pageDownFlag=true;
	        }
	        if(pageUpFlag || pageDownFlag){
	            int locateIndex=0;//当前xh在新的查询数据中的位置
	            //遇到分页的时候就多查点数据
	            List<Vehicle> vehicles=YxxxServiceImpl.queryVehicleList(
	                    info,startTime,endTime,page);
	            int size=vehicles.size();
	            for(int i=0;i<size;i++){
	                Vehicle tempVehicle=vehicles.get(i);
	                String newXh=tempVehicle.getXh();
	                if(currentXh.equals(newXh)){
	                    locateIndex=i;
	                }
	                if(i==0){
	                    xhs=newXh;
	                }else{
	                    xhs=xhs+","+newXh;
	                }
	            }
	            if(pageUpFlag){
	                //上一页
	                preXh=vehicles.get(locateIndex-1).getXh();
	            }else if(pageDownFlag){
	                //下一页
	                if(locateIndex+1<size){
	                    nextXh=vehicles.get(locateIndex+1).getXh();
	                }
	            }
	        }
			info.setXh(currentXh);
			info=YxxxServiceImpl.findYxshByxhFirstIn(info,startTime,endTime);
			Document doc=null;
			try {
				doc = DocumentHelper.parseText(info.getTpurl()==null?"":info.getTpurl());
			} catch (DocumentException e1) {
				e1.printStackTrace();
			}
			List<Vehicle> listTpurl = new ArrayList<Vehicle>(); //存放图片列表对象
			Map<Integer,Integer> map = new HashMap<Integer,Integer>();
			for(int i=1;i<8;i++){ //初始化各个档案类型数量
				map.put(i, 0);
			}
			if(null!=doc){
				Element root = doc.getRootElement();
				List nodes = root.elements();
				for (Iterator<?> it = nodes.iterator(); it.hasNext();) {
					Vehicle obj =new Vehicle();
					Element e = (Element) it.next();
					String key = e.attributeValue("id");
					obj.setId(key);
					try {
						obj.setSingleIpaddress(toHexString(encrypt(e.getStringValue(), "ahhwxxjs")).toUpperCase());
					} catch (Exception e1) {
						e1.printStackTrace();
					}
					
					
					listTpurl.add(obj);
					/*//统计相同id数量
					if(map.containsKey(Integer.parseInt(key))){
						map.put(Integer.parseInt(key), map.get(key).intValue()+1);*/
				}
				
				for( Entry<Integer, Integer> mapTemp : map.entrySet()){
					/*if(mapTemp.getKey().toString().equals(key)){
						map.put(mapTemp.getKey(), mapTemp.getValue().intValue()+1);
						//obj.setIdNums(mapTemp.getValue()+1);
					}*/
					for(Vehicle list : listTpurl){
						if(mapTemp.getKey().toString().equals(list.getId())){
							map.put(mapTemp.getKey(), mapTemp.getValue().intValue()+1);
						}
					}					
				}
				 //ArrayList<Integer> newList = new ArrayList<Integer>(map.values());
				//idNums = (ArrayList<Integer>) map.values();
				//for(Integer dd :idNums){
				//System.out.println(newList.toString());
				//}
			}
			mv.addObject("tpNums", map);
			mv.addObject("listTpurl",listTpurl);
			mv.addObject("info",info);
			mv.addObject("preXh",preXh);
			mv.addObject("xhs",xhs);
			mv.addObject("nextXh",nextXh);
			mv.addObject("startTime",startTime);
			mv.addObject("endTime",endTime);
			mv.addObject("pageInfo",page);
			return mv;
		}
	 
	/**
	 * 查询影像审核档案详情，控制翻页
	 * @param request
	 * @param response
	 * @param info
	 */
	/*@RequestMapping(method=RequestMethod.GET)
	public ModelAndView findYxshByxhUpAndDown(HttpServletRequest request,HttpServletResponse response,GcPage<Vehicle> pages,
			Vehicle info,String startTime,String endTime){
		 GcPage<Vehicle> page=YxxxServiceImpl.findYxshByxhUpAndDown(pages,info,startTime,endTime);
		 ModelAndView mv = new ModelAndView("yxsh/vehicle/yxshxq");
			Document doc=null;
			try {
				doc = DocumentHelper.parseText(page.getRows().get(0).getTpurl());
			} catch (DocumentException e1) {
				e1.printStackTrace();
			}
			 Element root = doc.getRootElement();
			 List nodes = root.elements();
			 List<Vehicle> listTpurl = new ArrayList<Vehicle>();
			 for (Iterator<?> it = nodes.iterator(); it.hasNext();) {
				 Vehicle obj =new Vehicle();
			 Element e = (Element) it.next();
			 obj.setId(e.attributeValue("id"));
			 obj.setSingleIpaddress(e.getStringValue());
			 listTpurl.add(obj);
			 }
			mv.addObject("list",listTpurl);
			mv.addObject("page",page);
			mv.addObject("startTime",startTime);
			mv.addObject("endTime",endTime);
			mv.addObject("vehicleObj",page.getRows().get(0));
			return mv;
	}*/
	/**
	 * 查询影像审核关联图片
	 * @param request
	 * @param response
	 * @param info
	 */
	@RequestMapping(method=RequestMethod.POST)
	public void findYxshRelation(HttpServletRequest request,HttpServletResponse response,Vehicle info){
		 List<Vehicle> list=YxxxServiceImpl.findYxshByxh(info);
		ControllerUtil.renderJson(response, list, "encoding:UTF-8", "no-cache:false");
	}
	/**
	 * 机动车档案审核
	 * @param request
	 * @param response
	 * @param info
	 */
	@RequestMapping(method=RequestMethod.POST)
	public void updateYxshzt(HttpServletRequest request,HttpServletResponse response,Vehicle info){
		 boolean flag=YxxxServiceImpl.updateYxshzt(info);
		 if(flag){
			 ControllerUtil.renderJson(response, "true", "encoding:UTF-8", "no-cache:false");
		 }else{
			 ControllerUtil.renderJson(response, "false", "encoding:UTF-8", "no-cache:false");
		 }
	}
	
	/**
	 * 跳转到机动车影像采集页面
	 */
	@RequestMapping(method=RequestMethod.GET)
	public String vehicleYxcj(HttpServletResponse response){
		return "yxcj/vehicle/yxcj";
	}
	
	/**
	 * 分页显示影像采集信息
	 */
	@RequestMapping(method=RequestMethod.POST)
	public void findYxcjPage(HttpServletRequest request,HttpServletResponse response,
								Page<Vehicle> pages,Vehicle info,String startTime,String endTime){
		Page<Vehicle> list = YxxxServiceImpl.findYxcjxx(pages, info,startTime,endTime);
		ControllerUtil.renderJson(response, list, "encoding:UTF-8","no-cache:false");
	}
	
	/**
	 * 根据已录入机动车进入影像采集档案编辑
	 * @param request
	 * @param response
	 */
	@RequestMapping(method = RequestMethod.GET)
	public ModelAndView findYxcjByxhFirstIn(HttpServletRequest request,HttpServletResponse response,PageUtil page,
			Vehicle info,String startTime,String endTime,String lshs){
		ModelAndView mv = new ModelAndView("yxcj/vehicle/checkyxcj2");
		String lsh=info.getLsh();
		String preLsh="";//上一个序号
		String currentLsh="";//当前序号
		String nextLsh="";//下一个序号
		if(StringUtils.isNotEmpty(lsh)){
		    String[] lshArr=lsh.split(",");
		    preLsh=lshArr[0];
		    currentLsh=lshArr[1];
		    nextLsh=lshArr[2];
		}
		//只有到了边界，才需要查询数据
		boolean pageUpFlag=false;
        boolean pageDownFlag=false;
        Long pageNumber=page.getCurrentPage();//当前页数
        Long totalPage=page.getTotalPage();//总页数
        if(preLsh.equals("0") && pageNumber>1){
            //如果pageUp为0,证明当前xh已经是当前页面第一条记录，这时应该查询上一页的数据
            pageUpFlag=true;
        }else if(nextLsh.equals("0") && pageNumber<=totalPage){
            //且不是最后一页
            //如果pageDown为0,证明当前页面已经走到最后一条记录了，这时应该查询下一页的数据
            pageDownFlag=true;
        }
        if(pageUpFlag || pageDownFlag){
            int locateIndex=0;//当前xh在新的查询数据中的位置
            //遇到分页的时候就多查点数据
            List<Vehicle> vehicles=YxxxServiceImpl.queryVehicleList(
                    info,startTime,endTime,page);
            int size=vehicles.size();
            for(int i=0;i<size;i++){
                Vehicle tempVehicle=vehicles.get(i);
                String newLsh=tempVehicle.getLsh();
                if(currentLsh.equals(newLsh)){
                    locateIndex=i;
                }
                if(i==0){
                    lshs=newLsh;
                }else{
                    lshs=lshs+","+newLsh;
                }
            }
            if(pageUpFlag){
                //上一页
            	if(locateIndex==0)
            		preLsh=vehicles.get(locateIndex).getLsh();
            	else
            		preLsh=vehicles.get(locateIndex-1).getLsh();
            }else if(pageDownFlag){
                //下一页
                if(locateIndex+1<size){
                    nextLsh=vehicles.get(locateIndex+1).getLsh();
                }
            }
        }
		info.setLsh(currentLsh);
		info=YxxxServiceImpl.findYxcjByxhFirstIn(info,startTime,endTime);
		//transfCodeToName(info);
		mv.addObject("info",info);
		mv.addObject("preLsh",preLsh);
		mv.addObject("lshs",lshs);
		mv.addObject("nextLsh",nextLsh);
		mv.addObject("startTime",startTime);
		mv.addObject("endTime",endTime);
		mv.addObject("pageInfo",page);
		return mv;
	}
	private void transfCodeToName(Vehicle vehicle) {
		String hpzl=vehicle.getHpzl();
		String hpzlmc=FrmCodeServiceImpl.hpzlMap.get(hpzl);//号牌种类
		vehicle.setHpzlmc(hpzlmc);
		String csys=vehicle.getCsys();
		String csysmc=FrmCodeServiceImpl.clysMap.get(csys);//车身颜色
		vehicle.setCsysmc(csysmc);
	}
	/**
	 * 根据已录入驾驶证进入影像采集档案编辑
	 * @param request
	 * @param response
	 */
	/*@RequestMapping(method = RequestMethod.GET)
	public ModelAndView findDriverYxcj(HttpServletRequest request,HttpServletResponse response,GcPage<DriverView> pages,
			DriverView info,String startTime,String endTime){
		ModelAndView mv = new ModelAndView("yxcj/driver/checkyxcj2");
		GcPage<DriverView> list=YxxxServiceImpl.findDriverYxcjFirstIn(pages,info,startTime,endTime);
		mv.addObject("list",list.getRows().get(0));
		mv.addObject("page",list);
		mv.addObject("startTime",startTime);
		mv.addObject("endTime",endTime);
		mv.addObject("sfzmhm",info.getSfzmhm());
		mv.addObject("dazt",info.getDazt());
		return mv;
	}*/
	/**
	 * 根据过车辆序号查询机动车采集页面，控制翻页
	 * @param request
	 * @param response
	 * @param info
	 */
	/*@RequestMapping(method=RequestMethod.GET)
	public void findYxcjByxhUpAndDown(HttpServletRequest request,HttpServletResponse response,GcPage<Vehicle> pages,
			Vehicle info,String startTime,String endTime){
		 GcPage<Vehicle> page=YxxxServiceImpl.findYxcjByxhUpAndDown(pages,info,startTime,endTime);
		ControllerUtil.renderJson(response, page, "encoding:UTF-8", "no-cache:false");
	}*/
	/**
	 * 查询机动车采集关联图片
	 * @param request
	 * @param response
	 * @param info
	 */
	@RequestMapping(method=RequestMethod.POST)
	public void findYxcjRelation(HttpServletRequest request,HttpServletResponse response,Vehicle info){
		 List<Vehicle> list=YxxxServiceImpl.findYxcjByxh(info);
		ControllerUtil.renderJson(response, list, "encoding:UTF-8", "no-cache:false");
	}
	/**
	 * 根据过车辆序号查询驾驶证采集页面，控制翻页
	 * @param request
	 * @param response
	 * @param info
	 */
	/*@RequestMapping(method=RequestMethod.GET)
	public void findDriverYxcjByxhUpAndDown(HttpServletRequest request,HttpServletResponse response,GcPage<DriverView> pages,
			DriverView info,String startTime,String endTime){
		 GcPage<DriverView> page=YxxxServiceImpl.findDriverYxcjByxhUpAndDown(pages,info,startTime,endTime);
		ControllerUtil.renderJson(response, page, "encoding:UTF-8", "no-cache:false");
	}*/
	/**
	 * 查询驾驶证采集关联图片
	 * @param request
	 * @param response
	 * @param info
	 */
	@RequestMapping(method=RequestMethod.POST)
	public void findDriverYxcjRelation(HttpServletRequest request,HttpServletResponse response,DriverView info){
		 List<DriverView> list=YxxxServiceImpl.findDriverYxcjByxh(info);
		ControllerUtil.renderJson(response, list, "encoding:UTF-8", "no-cache:false");
	}
	@RequestMapping(method=RequestMethod.POST)
	public void updateYxcjRelation(HttpServletRequest request,HttpServletResponse response,String xh,@RequestParam("tpurlarray[]") String[] tpurlarray){
		 boolean flag=YxxxServiceImpl.updateYxcjByxh(xh.trim(),tpurlarray);
		ControllerUtil.renderJson(response, flag, "encoding:UTF-8", "no-cache:false");
	}
	/**
	 * 查询机动车信息
	 * @param request
	 * @param response
	 * @param info
	 */
	@RequestMapping(method=RequestMethod.POST)
	public void queryVehcile(HttpServletRequest request,HttpServletResponse response,Vehicle info){
	    Sys_Role sysRole=(Sys_Role)request.getSession().getAttribute("role");
	    List<Vehicle> vehicleList=YxxxServiceImpl.queryVehcileLsList(info,sysRole);
		ControllerUtil.renderJson(response, vehicleList, "encoding:UTF-8", "no-cache:false");
	}
	/**
	 * 查询当前流水档案是否已录入
	 * @param request
	 * @param response
	 * @param info
	 */
	@RequestMapping(method=RequestMethod.POST)
	public void queryVehcileIsNot(HttpServletRequest request,HttpServletResponse response,String lsh,String xh){
	    boolean flag=YxxxServiceImpl.queryVehcileIsNot(lsh,xh);
		ControllerUtil.renderJson(response, flag, "encoding:UTF-8", "no-cache:false");
	}
	/**
	 * 根据车辆记录首次进入机动车档案编辑页面
	 * @param request
	 * @param response
	 */
	@RequestMapping(method = RequestMethod.GET)
	public String VehicleYxcjByhphmAndhpzl(HttpServletRequest request,HttpServletResponse response){
		/*ModelAndView mv = new ModelAndView("yxcj/vehicle/checkyxcj");
		Vehicle obj=YxxxServiceImpl.queryVehcileByHphmAndHpzl(info);
		mv.addObject("list",obj);
		return mv;*/
		return "yxcj/vehicle/checkyxcj";
	}
	
	/**
	 * 跳转到驾驶证采集页面
	 */
	@RequestMapping(method=RequestMethod.GET)
	public String driverYxcj(HttpServletResponse response){
		return "yxcj/driver/yxcj";
	}
	/**
	 * 查询驾驶证信息
	 * @param request
	 * @param response
	 * @param info
	 */
	/*@RequestMapping(method=RequestMethod.POST)
	public void queryDriver(HttpServletRequest request,HttpServletResponse response,DriverView info){
		DriverView driver=YxxxServiceImpl.queryDriverBysfzmhm(info);
		ControllerUtil.renderJson(response, driver, "encoding:UTF-8", "no-cache:false");
	}*/

	/**
	 * 删除档案记录
	 * @param response
	 */
	@RequestMapping(method = RequestMethod.POST)
	public void delVehicle(HttpServletResponse response,String xh,String lsh,String bussinessType){
		int num=YxxxServiceImpl.delVehcile(xh,lsh,bussinessType);
		ControllerUtil.renderJson(response, num, "encoding:UTF-8", "no-cache:false");
	}
	/**
	 * 根据车辆记录首次进入驾驶证档案编辑页面
	 * @param request
	 * @param response
	 */
	/*@RequestMapping(method = RequestMethod.GET)
	public ModelAndView DriverYxcjBysfzmhm(HttpServletRequest request,HttpServletResponse response,DriverView info){
		ModelAndView mv = new ModelAndView("yxcj/driver/checkyxcj");
		DriverView obj=YxxxServiceImpl.queryDriverOBjBysfzmhm(info);
		mv.addObject("list",obj);
		return mv;
	}*/
	/**
	 * 分页显示驾驶证档案采集信息
	 */
	@RequestMapping(method=RequestMethod.POST)
	public void findDriverYxcjPage(HttpServletRequest request,HttpServletResponse response,
								Page<DriverView> pages,DriverView info,String startTime,String endTime){
		Page<DriverView> list = YxxxServiceImpl.findDriverYxcjxx(pages, info,startTime,endTime);
		ControllerUtil.renderJson(response, list, "encoding:UTF-8","no-cache:false");
	}
	
	/**
	 * 跳转到驾驶证审核列表页面
	 */
	@RequestMapping(method=RequestMethod.GET)
	public String driveryxsh(HttpServletResponse response){
		return "yxsh/driver/Driveryxsh";
	}
	/**
	 * 分页显示驾驶证档案审核列表
	 */
	@RequestMapping(method=RequestMethod.POST)	
	public void findDriverYxshPage(HttpServletRequest request,HttpServletResponse response,
								Page<DriverView> pages,DriverView info,String startTime,String endTime){
		Sys_User user=(Sys_User) request.getSession().getAttribute("user");
		Page<DriverView> list = YxxxServiceImpl.finddriverYxshxx(pages, info,startTime,endTime,user);
		ControllerUtil.renderJson(response, list, "encoding:UTF-8","no-cache:false");
	}
	/**
	 * 驾驶证档案审核详情
	 * @param request
	 * @param response
	 * @param page
	 * @param info
	 * @param startTime
	 * @param endTime
	 * @param xhs
	 * @return
	 */
		/*@RequestMapping(method = RequestMethod.GET)
		public ModelAndView findDriverYxshFirstIn(HttpServletRequest request,HttpServletResponse response,PageUtil page,
				DriverView info,String startTime,String endTime,String xhs){
			ModelAndView mv = new ModelAndView("yxsh/driver/DriveryxshxqAction");
			String xh=info.getXh();
			String preXh="";//上一个序号
			String currentXh="";//当前序号
			String nextXh="";//下一个序号
			if(StringUtils.isNotEmpty(xh)){
			    String[] xhArr=xh.split(",");
			    preXh=xhArr[0];
			    currentXh=xhArr[1];
			    nextXh=xhArr[2];
			}
			//只有到了边界，才需要查询数据
			boolean pageUpFlag=false;
	        boolean pageDownFlag=false;
	        Long pageNumber=page.getCurrentPage();//当前页数
	        Long totalPage=page.getTotalPage();//总页数
	        if(preXh.equals("0") && pageNumber>1){
	            //如果pageUp为0,证明当前xh已经是当前页面第一条记录，这时应该查询上一页的数据
	            pageUpFlag=true;
	        }else if(nextXh.equals("0") && pageNumber<=totalPage){
	            //且不是最后一页
	            //如果pageDown为0,证明当前页面已经走到最后一条记录了，这时应该查询下一页的数据
	            pageDownFlag=true;
	        }
	        if(pageUpFlag || pageDownFlag){
	            int locateIndex=0;//当前xh在新的查询数据中的位置
	            //遇到分页的时候就多查点数据
	            List<DriverView> vehicles=YxxxServiceImpl.queryDriverList(
	                    info,startTime,endTime,page);
	            int size=vehicles.size();
	            for(int i=0;i<size;i++){
	            	DriverView tempVehicle=vehicles.get(i);
	                String newXh=tempVehicle.getXh();
	                if(currentXh.equals(newXh)){
	                    locateIndex=i;
	                }
	                if(i==0){
	                    xhs=newXh;
	                }else{
	                    xhs=xhs+","+newXh;
	                }
	            }
	            if(pageUpFlag){
	                //上一页
	                preXh=vehicles.get(locateIndex-1).getXh();
	            }else if(pageDownFlag){
	                //下一页
	                if(locateIndex+1<size){
	                    nextXh=vehicles.get(locateIndex+1).getXh();
	                }
	            }
	        }
			info.setXh(currentXh);
			info=YxxxServiceImpl.findDriverYxshFirstIn(info,startTime,endTime);
			Document doc=null;
			try {
				doc = DocumentHelper.parseText(info.getTpurl()==null?"":info.getTpurl());
			} catch (DocumentException e1) {
				e1.printStackTrace();
			}
			List<DriverView> listTpurl = new ArrayList<DriverView>();
			if(null!=doc){
				Element root = doc.getRootElement();
				List nodes = root.elements();

				for (Iterator<?> it = nodes.iterator(); it.hasNext();) {
					DriverView obj =new DriverView();
					Element e = (Element) it.next();
					obj.setId(e.attributeValue("id"));
					try {
						obj.setSingleIpaddress(toHexString(encrypt(e.getStringValue(), "ahhwxxjs")).toUpperCase());
					} catch (Exception e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
					listTpurl.add(obj);
				}
			}

			mv.addObject("listTpurl",listTpurl);
			mv.addObject("info",info);
			mv.addObject("preXh",preXh);
			mv.addObject("xhs",xhs);
			mv.addObject("nextXh",nextXh);
			mv.addObject("startTime",startTime);
			mv.addObject("endTime",endTime);
			mv.addObject("pageInfo",page);
			return mv;
		}*/
		/**
		 * 驾驶证档案审核
		 * @param request
		 * @param response
		 * @param info
		 */
		@RequestMapping(method=RequestMethod.POST)
		public void updateDriverYxshzt(HttpServletRequest request,HttpServletResponse response,DriverView info){
			 boolean flag=YxxxServiceImpl.updateDriverYxshzt(info);
			 if(flag){
				 ControllerUtil.renderJson(response, "true", "encoding:UTF-8", "no-cache:false");
			 }else{
				 ControllerUtil.renderJson(response, "false", "encoding:UTF-8", "no-cache:false");
			 }
		}
		
		@RequestMapping(method=RequestMethod.POST)
		public void queryVehcileRecode(HttpServletRequest request,HttpServletResponse response,Vehicle info){
		    Sys_Role sysRole=(Sys_Role)request.getSession().getAttribute("role");
		    List<Vehicle> vehicleList=YxxxServiceImpl.queryVehcileRecodeList(info,sysRole);
			ControllerUtil.renderJson(response, vehicleList, "encoding:UTF-8", "no-cache:false");
		}
		
		@RequestMapping(method=RequestMethod.POST)
		public void queryVehcileNotFlow(HttpServletRequest request,HttpServletResponse response,Vehicle info){
		    Vehicle vehicle=YxxxServiceImpl.queryVehcileNotFlowObj(info);
			ControllerUtil.renderJson(response, vehicle, "encoding:UTF-8", "no-cache:false");
		}
		@RequestMapping(method=RequestMethod.POST)
		public void queryYwlx(HttpServletRequest request,HttpServletResponse response,Vehicle info){
		    List<Vehicle> vehicle=YxxxServiceImpl.queryYwlxList(info);
			ControllerUtil.renderJson(response, vehicle, "encoding:UTF-8", "no-cache:false");
		}
		@RequestMapping(method=RequestMethod.POST)
		public void queryYwyy(HttpServletRequest request,HttpServletResponse response,Vehicle info){
		    List<Vehicle> vehicle=YxxxServiceImpl.queryYwyyList(info);
			ControllerUtil.renderJson(response, vehicle, "encoding:UTF-8", "no-cache:false");
		}
		/**
		 * 
		 * @param request
		 * @param response
		 * @param info
		 */
		@RequestMapping(method=RequestMethod.POST)
		public void validateSbxh(HttpServletRequest request,HttpServletResponse response,String sbxh){
		    boolean flag=YxxxServiceImpl.validateSbxh(sbxh);
			ControllerUtil.renderJson(response, flag, "encoding:UTF-8", "no-cache:false");
		}
}
